package com.mojian.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mojian.annotation.OperationLogger;
import com.mojian.common.Result;
import com.mojian.dto.user.SysUserPlatformBatchDto;
import com.mojian.dto.user.SysUserPlatformDto;
import com.mojian.entity.SysUserPlatform;
import com.mojian.service.SysUserPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: yuzhuo
 * @date: 2025/6/6
 * @description: 用户社交平台控制器
 */
@RestController
@RequestMapping("/sys/user")
@RequiredArgsConstructor
@Api(tags = "用户社交平台管理")
public class SysUserSocialMedia {

    private final SysUserPlatformService sysUserPlatformService;

    @GetMapping("/{userId}/socialMedia")
    @ApiOperation(value = "获取用户社交平台列表")
    public Result<List<SysUserPlatform>> getUserSocialMediaList(
            @ApiParam(value = "用户ID", required = true) @PathVariable Long userId) {
        List<SysUserPlatform> platforms = sysUserPlatformService.getUserSocialMediaList(userId);
        return Result.success(platforms);
    }

    @PostMapping("/socialMedia")
    @OperationLogger("添加用户社交平台")
    @ApiOperation(value = "添加用户社交平台")
    // @SaCheckPermission("sys:user:socialMedia:add")
    public Result<Boolean> createUserSocialMedia(
            @ApiParam(value = "社交平台信息", required = true) @Valid @RequestBody SysUserPlatformDto dto) {
        Boolean result = sysUserPlatformService.createUserSocialMedia(dto);
        return Result.success(result);
    }

    @PutMapping("/socialMedia")
    @OperationLogger("修改用户社交平台")
    @ApiOperation(value = "修改用户社交平台")
    // @SaCheckPermission("sys:user:socialMedia:update")
    public Result<Boolean> updateUserSocialMedia(
            @ApiParam(value = "社交平台信息", required = true) @Valid @RequestBody SysUserPlatformDto dto) {
        Boolean result = sysUserPlatformService.updateUserSocialMedia(dto);
        return Result.success(result);
    }

    @DeleteMapping("/socialMedia/{id}")
    @OperationLogger("删除用户社交平台")
    @ApiOperation(value = "删除用户社交平台")
    // @SaCheckPermission("sys:user:socialMedia:delete")
    public Result<Boolean> deleteUserSocialMedia(
            @ApiParam(value = "社交平台ID", required = true) @PathVariable Long id) {
        Boolean result = sysUserPlatformService.deleteUserSocialMedia(id);
        return Result.success(result);
    }

    @PostMapping("/socialMedia/batch")
    @OperationLogger("批量保存用户社交平台")
    @ApiOperation(value = "批量保存用户社交平台")
    // @SaCheckPermission("sys:user:socialMedia:batch")
    public Result<Boolean> batchSaveUserSocialMedia(
            @ApiParam(value = "批量保存信息", required = true) @Valid @RequestBody SysUserPlatformBatchDto dto) {
        Boolean result = sysUserPlatformService.batchSaveUserSocialMedia(dto);
        return Result.success(result);
    }
}
